<template>
	<view class="main_bg" v-if="info.id">
		<app-header title="巡检详情"></app-header>
		<view class="card">
			<view class="cell">
				<view class="label">状态：</view>
				<view class="value" :class="['inspection_status_'+info.inspection_status]">{{info.status_name}}</view>
			</view>
			<view class="line"></view>
			<view class="cell">
				<view class="label flex-c">
					巡检计划编号：
				</view>
				<view class="value">{{info.device_sns}}</view>
			</view>
			<view class="cell">
				<view class="label">巡检名称：</view>
				<view class="value">{{info.title}}</view>
			</view>
			<view class="cell">
				<view class="label">巡检对象：</view>
				<view class="value">{{info.shop_name_f}}</view>
			</view>
			<view class="cell">
				<view class="label">巡检地点：</view>
				<view class="value" @click="$func.openLocation(info.latitude,info.longitude,info.address_f)">
					{{info.address_f}} <u-image src="/static/images/guide.png" mode="aspectFit" width="40rpx"
						height="40rpx"></u-image>
				</view>
			</view>
			<view class="cell">
				<view class="label">预计巡检时间：</view>
				<view class="value">{{info.action_start}}至{{info.action_end}}</view>
			</view>
			<view class="cell">
				<view class="label">巡检人员：</view>
				<view class="value ">{{info.name_f}}</view>
			</view>

			<!-- <view v-if="info.inspection_status==0">
				<view class="line"></view>
				<view class="cell">
					<view class="label">巡检反馈建议：</view>
					<view class="value flex-s scan" @click="scanCode"> 扫码选择设备 <u-icon name="scan" color="#F68C4F"
							size="48rpx"></u-icon></view>
				</view>
				<view v-for="(item,index) in form" :key="index">

					<view class="tags flex-c" v-if="item.device_name">
						<view class="tags_son flex-c">
							{{item.device_name}}
						</view>
					</view>
					<view class="textarea">
						<textarea v-model="item.member_describe" placeholder="请输入"></textarea>
					</view>
					<view class="line"></view>
					<view class="cell">
						<view class="label">巡检图片({{imgCount(form.member_store_imgs)}}/9)</view>
					</view>
					<view class="upload">
						<app-upload v-model="item.member_store_imgs" :value="form.member_store_imgs" accept="file"
							multiple :maxCount="9">
						</app-upload>
					</view>
					<view class="line"></view>
				</view>
			</view> -->

			<view v-if="info.inspection_status==1">
				<view class="line"></view>
				<!-- <view class="cell">
					<view class="label">巡检反馈建议：</view>
				</view>
				<view v-for="(item,index) in info.order_list" :key="index">

					<view class="tags flex-c" v-if="item.device_name">
						<view class="tags_son flex-c">
							{{item.device_name}}
						</view>
					</view>
					<view class="textarea">
						{{item.member_describe_s}}
					</view>

					<view class="cell">
						<view class="label">巡检图片</view>
					</view>
					<view class="upload">
						<view class="imgs_list flex-c" v-if="item.member_imgs_ff&&item.member_imgs_ff.length>0">
							<view class="imgs_son" v-for="(vo,idx) in item.member_imgs_ff" :key="idx">
								<u-image :src="vo" mode="aspectFill" width="100px" height="100px"
									@click="$func.previewImage(vo,item.member_imgs_ff)"></u-image>
							</view>
						</view>
					</view>
					<view class="line"></view>
				</view> -->
				<view class="cell">
					<view class="label">实际巡检时间：</view>
					<view class="value">{{info.dotime}}</view>
				</view>
			</view>

			<view class="line"></view>
			<view style="display: flex;flex-direction: column;gap:30rpx;margin-top:20rpx">
				<view style="color:#333;font-size:28rpx;">巡检设备：</view>
				<view style="display: flex;flex-direction: column;gap:30rpx;max-height:800rpx;overflow: auto;">
					<view v-for="(obj,j) in info.order_list" :key="j"
						style="display: flex;gap:10rpx;align-items: center;justify-content: space-between;">
						<view style="flex:1;font-size:28rpx;">{{obj.device_name}}</view>
						<view style="display: flex;gap:10rpx;">
							<view
								@click.stop="$func.toUrl(obj.member_describe_s!=''?'/pages_user/inspections/maintain?id='+obj.id:'')"
								:style="obj.member_describe_s!=''?'background:#4F6FF6':'background:#ADADAD'"
								style='border-radius:10rpx;padding:20rpx 17rpx;font-size:30rpx;color:white'>
								保养单
							</view>
							<view
								@click.stop="$func.toUrl(obj.has_fault==1?'/pages_user/inspections/fault?id='+obj.id:'')"
								:style="obj.has_fault==1?'background:#4F6FF6':'background:#ADADAD'"
								style='border-radius:10rpx;padding:20rpx 17rpx;font-size:30rpx;color:white'>
								故障单
							</view>
						</view>
					</view>
				</view>
			</view>

		</view>

	</view>
</template>

<script>
	const systemInfo = uni.getSystemInfoSync();
	const safeArea = systemInfo.safeArea;
	export default {
		name: "deviceCard",

		data() {
			return {
				id: 0,
				info: {},
				form: [{
					device_id: "",
					member_describe: "",
					member_store_imgs: "",
				}]
			};
		},
		computed: {
			scrollHeight() {
				return 'calc(100vh   - 102rpx)'
			},
			imgCount() {
				return (imgs) => {
					const list = imgs ? imgs.split('|') : []
					return list.length
				}
			},
			imageList() {
				return (imgs) => {
					console.log(imgs)
					const list = imgs ? imgs.split('|') : []
					return list
				}
			}
		},
		onLoad(options) {
			this.id = options.id
			this.getInfo()
		},
		methods: {
			scanCode() {
				uni.scanCode({
					success: (res) => {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						const info = this.form.find(item => item.device_id == res.result)
						if (info) {
							this.$func.tips("该设备已在巡检记录中")
						} else {
							this.formAdd(res.result)
						}
					}
				});
			},
			formAdd(id) {
				this.$http.post('/data/api.auth.User/inspectionDetection', {
					id: this.id,
					device_id: id
				}).then(res => {

					this.$http.post('/data/api.auth.User/deviceVier', {
						id: id
					}).then(res => {
						if (this.form.length > 0 && !this.form[0].device_id) {
							this.form = [{
								device_id: id,
								device_name: res.data.device_name,
								member_describe: "",
								member_store_imgs: "",
							}]
						} else {
							this.form.push({
								device_id: id,
								device_name: res.data.device_name,
								member_describe: "",
								member_store_imgs: "",
							})
						}
					})
				})


			},
			getInfo() {
				this.$http.post('/data/api.auth.User/inspectionView', {
					id: this.id,
				}).then(res => {
					this.info = res.data
					if (!(res.data.order_list && res.data.order_list.length > 0)) {
						this.info.order_list = [{
							member_describe_s: res.data.member_describe,
							member_imgs_ff: res.data.member_store_imgs ? res.data.member_store_imgs.split(
								"|") : []
						}]
					}

				}).catch(() => {

				})


			},

		}
	}
</script>

<style scoped lang="scss">
	.tags {
		justify-content: flex-start;
		margin-bottom: 10rpx;

		.tags_son {
			padding: 0 20rpx;
			min-width: 200rpx;
			height: 70rpx;
			border: 1px solid #ADADAD;
			border-radius: 10rpx;
		}
	}

	.card {
		border-radius: 20px;
		background-color: #FFFFFF;
		margin: 20rpx;
		padding: 20rpx 30rpx;
	}

	.textarea {
		background-color: #F5F5F5;
		border-radius: 10rpx;
		padding: 20rpx;
	}

	.line {
		background-color: #E9E9E9;
		height: 1px;
		margin: 15rpx 0;
	}

	.icon {
		transition-duration: 0.3s;
		width: 40rpx;
		height: 40rpx;

		&.open {
			transform: rotate(180deg);
		}
	}

	.imgs_list {
		padding: 5px 0;
		justify-content: flex-start;

		.imgs_son {
			margin: 0 8px 0 0;
			border-radius: 4px;
			overflow: hidden;
		}
	}

	.cell {
		// height: 60rpx;

		.label {
			color: #333333;
		}

		.value {
			color: #ADADAD;

			&.scan {
				color: #F68C4F;
				justify-content: flex-end;
			}
		}
	}

	.btn {
		width: 300rpx;
		height: 80rpx;

		background-color: #4F6FF6;

		border-radius: 10rpx;
		font-size: 30rpx;

		color: #FFFFFF;
		margin: 40rpx 20rpx 50rpx;

		&:nth-child(1) {
			background-color: #ADADAD;
		}
	}
</style>